/**
 * createStore
 * @param reducer funct
 */
const createStore = (reducer = () => {}, e) => {
    if(e){
        return e(createStore)(reducer);
    }
    let state = {};
    const listeners = [];

    const getState = () => {
        return state;
    };

    const subscribe = (funct = () => {}) => {
        listeners.push(funct);
    };

    const dispatch = (action = {}) => {
        state = reducer(state, action);
        listeners.forEach(v => v());
        return action;
    };

    dispatch({type: 'ak47'});

    return {
        getState,
        subscribe,
        dispatch
    }
};

export { createStore };